import unittest
import time
import HTMLTestRunner

discover = unittest.defaultTestLoader.discover(r'D:\python\Scripts\project\testApi\testCase', pattern="test*.py")
now = time.strftime('%Y-%m-%d %H_%M_%S')
report_name = now + 'report.html'
# 打开文件，写入测试结果
with open(f'D:\\python\\Scripts\\project\\testApi\\reports\\{report_name}', 'wb') as f:
    runner = HTMLTestRunner.HTMLTestRunner(stream=f, title='接口测试报告', description='用例执行详细信息')
    runner.run(discover)

# testcase = unittest.TestSuite()
# discover = unittest.defaultTestLoader.discover(r'/', pattern="test*.py")
# # testcase.addTest(test_Config('test_config'))
# for test_suite in discover:
#     for test_case in test_suite:
#         testcase.addTest(test_case)
#         # print(testcase)
# now = time.strftime('%Y-%m-%d %H_%M_%S')
# report_name = now + 'report.html'
# # 打开文件，写入测试结果
# with open(f'D:\\python\\Scripts\\project\\testApi\\reports\\{report_name}', 'wb') as f:
#     runner = HTMLTestRunner.HTMLTestRunner(stream=f, title='接口测试报告', description='用例执行详细信息')
#     runner.run(testcase)
#     f.close()
